package com.weavernorth.action.allflow;

import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

public class SapAction implements Action {
    /**
     * 流程路径节点后选择aciton后,会在节点提交后执行此方法。
     */
    @Override
    public String execute(RequestInfo requestInfo) {
        BaseBean bb  = new BaseBean();
        //1：获取表单的requestid
        String requestId = requestInfo.getRequestid();
        //2：获取表单名称tablename
        String tablename = requestInfo.getRequestManager().getBillTableName();
        //3：查找表单内容
        RecordSet rs = new RecordSet();
        //查询表单所有字段信息的sql
        rs.execute("select * from "+tablename+" where requestid =  "+requestId);
        rs.next();
        //从配置表中获取字段名称
        String strfhzt=Util.null2String(bb.getPropValue("actionurl","fhzt"));
        String strfhsm=Util.null2String(bb.getPropValue("actionurl","fhsm"));
        //取出sap返回状态
        String fhzt= Util.null2String(rs.getString(strfhzt));
        bb.writeLog("Sap返回状态="+fhzt);
        //如果返回状态strSapfhzt为E，流程失败提示
        if(fhzt.equals("E")){
            //取出sap返回说明
            String fhsm= Util.null2String(rs.getString(strfhsm));
            //流程失败，提示信息
            bb.writeLog("返回说明"+fhsm);
            requestInfo.getRequestManager().setMessagecontent(fhsm);
            return Action.FAILURE_AND_CONTINUE;
        }
        return SUCCESS;
    }
}
